import Taro from '@tarojs/taro';

/**
 * @desc 小程序升级插件
 */
class Upgrade {
  static updateManager = Taro.getUpdateManager();
  static updateReady() {
    Taro.showModal({
      title: '更新提示',
      content: '新版本已经准备好，是否重启应用？',
      success(res) {
        if (res.confirm) {
          Upgrade.updateManager.applyUpdate();
        }
      },
    });
  }

  static bootstrap() {
    Upgrade.updateManager.onUpdateReady(Upgrade.updateReady);
  }
}

export default Upgrade;
